package com.lzy.wzy.handle;

import com.lzy.wzy.exception.BingDingTemplateException;
import com.lzy.wzy.exception.DepartmentSelectionException;
import com.lzy.wzy.result.Response;
import com.lzy.wzy.result.ResponseCode;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.client.HttpClientErrorException;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.ValidationException;
import java.sql.SQLException;
import java.util.Set;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

//    @ExceptionHandler(value = SQLException.class)
//    public Response<T> invalidTokenMono() {
//        return new Response<>(ResponseCode.FAILURE.getCode(), ResponseCode.FAILURE.getMsg(), null);
//    }

    @ExceptionHandler(value = AccessDeniedException.class)
    public Response<T> forbidden(Exception e){
        log.info("--------------------------无权访问");
        return new Response<>(403, "无权访问", null);
    }
//
    @ExceptionHandler(value = RuntimeException.class)
    public Response<T> tryException(RuntimeException e){
        e.printStackTrace();
        return new Response<>(ResponseCode.FAILURE.getCode(), e.getMessage() ,null);
    }

    @ExceptionHandler(value = Exception.class)
    public Response<T> AllException(Exception e){
        e.printStackTrace();
        return new Response<>(ResponseCode.FAILURE.getCode(), "操作失败" ,null);
    }


//
//    @ExceptionHandler(value = BingDingTemplateException.class)
//    public Response<T> bingDingTemplate(BingDingTemplateException e) {
//        return new Response<>(ResponseCode.FAILURE.getCode(), e.getMessage(), null);
//    }
//
//    @ExceptionHandler(value = MethodArgumentNotValidException.class)
//    public Response<T> validationError(MethodArgumentNotValidException exception) {
//        log.info(exception.getMessage());
//        return new Response<>(ResponseCode.WRONG_FORMAT.getCode(), ResponseCode.WRONG_FORMAT.getMsg(), null);
//    }
//
//    @ExceptionHandler(value = DepartmentSelectionException.class)
//    public Response<T> departmentEx() {
//        log.info("departmentEx");
//        return new Response<>(ResponseCode.DEPARTMENT_ERROR.getCode(), ResponseCode.DEPARTMENT_ERROR.getMsg(), null);
//    }

}
